// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The cwkshell Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cuc/src/cwkshell/browser/shell_render_process_observer.h"

#include "base/command_line.h"
#include "content/public/renderer/render_thread.h"
#include "content/public/common/content_client.h"
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/render_thread.h"

#include "cuc/src/cwkshell/browser/shell_messages.h"
#include "cuc/src/cwkshell/browser/shell_content_renderer_client.h"


namespace cuc {
	namespace shell {


		namespace {
			ShellRenderProcessObserver* g_instance = NULL;
		}

		ShellRenderProcessObserver::ShellRenderProcessObserver() {
			CHECK(!g_instance);
			g_instance = this;  	
			content::RenderThread::Get()->AddObserver(this);
		}

		ShellRenderProcessObserver::~ShellRenderProcessObserver() {
		}

		void ShellRenderProcessObserver::WebKitInitialized() {
			LOG(INFO)<<"CALL";
			content::RenderThread::Get()->RegisterExtension(new CUCObject);
			
		}

		bool ShellRenderProcessObserver::
			OnControlMessageReceived( const IPC::Message& message ) 
		{
			bool handled = true;
			IPC_BEGIN_MESSAGE_MAP(ShellRenderProcessObserver, message)
				IPC_MESSAGE_HANDLER(ShellViewMsg_QuitApplication, OnQuitApplication)
				IPC_MESSAGE_HANDLER(ShellViewMsg_WindowMinimize,
				OnWindowMinimize)
				IPC_MESSAGE_HANDLER(ShellViewMsg_WindowMaxsize,
				OnWindowMaxsize)
				IPC_MESSAGE_UNHANDLED(handled = false)
				IPC_END_MESSAGE_MAP()
				return handled;
		}

		void ShellRenderProcessObserver::OnQuitApplication()
		{
			LOG(INFO)<<"CALL";
		}

		void ShellRenderProcessObserver::OnWindowMinimize()
		{

		}

		void ShellRenderProcessObserver::OnWindowMaxsize()
		{

		}

		ShellRenderProcessObserver* ShellRenderProcessObserver::GetInstance()
		{
			 return g_instance;
		}



	}  // namespace shell
}  // namespace cuc
